package com.xbenben.demo;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class TestDemo {

    //测试 合并
    public static void main(String[] args) {


//        Callable<List<String>> callable = new Callable<List<String>>() {
//            @Override
//            public List<String> call() throws Exception {
//
//                ArrayList<String> strings = new ArrayList<>();
//
//                strings.add("1");
//                strings.add("2");
//                strings.add("3");
//                strings.add("4");
//                Thread.sleep(5000);
//
//                return strings;
//            }
//        };


        //开始线程
        FutureTask<List<String>> listFutureTask = new FutureTask<>(() -> {

            ArrayList<String> strings = new ArrayList<>();

            return strings;
        });


        //开始线程
        FutureTask<List<String>> listFutureTask1 = new FutureTask<>(() -> {

            ArrayList<String> strings = new ArrayList<>();

            return strings;
        });


        new Thread(listFutureTask).start();
        System.out.println("第一阶段");
        new Thread(listFutureTask1).start();
        System.out.println("第二阶段");


        //          通过futuretask可以得到MyCallableTask的call()的运行结果：
        try {
            List<String> strings = listFutureTask.get();
            System.out.println(strings);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }

        //          通过futuretask可以得到MyCallableTask的call()的运行结果：
        try {
            List<String> strings = listFutureTask1.get();
            System.out.println(strings);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }


        System.out.println("结束");

    }
}
